from django.db import models

class OpenGraphObject(models.Model):
  
  def get_open_graph_type(self):
    raise NotImplementedError('OpenGraphObject subclasses must implement get_open_graph_type')
  
  def get_open_graph_title(self):
    raise NotImplementedError('OpenGraphObject subclasses must implement get_open_graph_title')
  
  def get_open_graph_url(self):
    raise NotImplementedError('OpenGraphObject subclasses must implement get_open_graph_url')
  
  def get_open_graph_images(self):
    raise NotImplementedError('OpenGraphObject subclasses must implement get_open_graph_image_url')
  
  def get_open_graph_audios(self):
    return ()
  
  def get_open_graph_videos(self):
    return ()
  
  def get_open_graph_description(self):
    return ''
  
  def get_open_graph_determiner(self):
    return ''
  
  def get_open_graph_attributes(self):
    attrs = []
    
    # Required attributes
    attrs.append(('og:title', self.get_open_graph_title()))
    attrs.append(('og:type', self.get_open_graph_type()))
    attrs.append(('og:url', self.get_open_graph_url()))
    
    # Image attributes (must have at least one image)
    for image in self.get_open_graph_images():
      attrs.append(('og:image', image['url']))
      attrs.append(('og:image:secure_url', image['secure_url']))
      attrs.append(('og:image:type', image['type']))
      attrs.append(('og:image:width', image['width']))
      attrs.append(('og:image:height', image['height']))
    
    # Video Attributes (optional)
    for video in self.get_open_graph_videos():
      attrs.append(('og:video', video['url']))
      attrs.append(('og:video:secure_url', video['secure_url']))
      attrs.append(('og:video:type', video['type']))
      attrs.append(('og:video:width', video['width']))
      attrs.append(('og:video:height', video['height']))
      
    # Audio Attributes (optional)
    for audio in self.get_open_graph_audios():
      attrs.append(('og:audio', audio['url']))
      attrs.append(('og:audio:secure_url', audio['secure_url']))
      attrs.append(('og:audio:type', audio['type']))
      
    # Optional Attributes
    attrs.append(('og:description', self.get_open_graph_description()))
    attrs.append(('og:determiner', self.get_open_graph_determiner()))
    
  
  class Meta:
    abstract = True
    
  
class OpenGraphObjectManager(models.Manager):
  
  def get_for_open_graph_urls(self, urls):
    raise NotImplementedError('OpenGraphObjectManager subclasses must implement get_for_open_graph_urls')
    
    
class OpenGraphAction:
  
  def get_open_graph_type(self):
    raise NotImplementedError('OpenGraphAction subclasses must implement get_open_graph_action')